include('shared.lua')

// Best material

local Laser = Material("tripmine_laser")

// Draw

function ENT:Draw()
	self.Entity:DrawModel()
	
	if (LocalPlayer():GetEyeTrace().Entity == self.Entity && EyePos():Distance(self.Entity:GetPos()) < 512) then
		if (self:IsEntityPressing()) then
			self:DrawEntityOutline(1.5 + math.sin(CurTime() * 50) * 0.5)
		else
			self:DrawEntityOutline(1.0)
		end
		
		if (self:GetOverlayText() != "") then
			AddWorldTip(self.Entity:EntIndex(), self:GetOverlayText(), 0.5, self.Entity:GetPos(), self.Entity)
		end
	end
	
	local Trace = {}
	
	Trace.start = self.Entity:GetPos()
	Trace.endpos = self.Entity:GetPos() + (self.Entity:GetUp() * self:GetEntityLength())
	Trace.filter = self.Entity

	local TR = util.TraceLine(Trace) 
	
	local Position = self.Entity:GetPos()
	
	render.SetMaterial(Laser)
	
	if (self:IsEntityPressing()) then
		render.DrawBeam(Position, TR.HitPos, 16, 0.2, 0.8, Color(0, 255, 0, 200))
	else
		render.DrawBeam(Position, TR.HitPos, 16, 0.2, 0.8, Color(255, 0, 0, 200))
	end
end